<template>
	<view>

		<view class="phone-title">
			修改密码后，需要重新登录
		</view>
		<view class="input-wrapper">
			<view class="zdy-input" style="margin-top: 20rpx;">
				<input class="pwd-left" :password="isShowPwd" name="password" placeholder="请输入原始密码"
					v-model="form.password1" />
				<view class="iconfont " style="color: #a6a6a6;"
					:class="[isShowPwd?'icon-app-yulan-close':'icon-app-yulan-open']" @click="switchIcon(1)"></view>
			</view>
			<view class="zdy-input">
				<input class="pwd-left" :password="isShowPwd2" name="password" placeholder="请输入字母/数字/字符组成的6-16位密码"
					v-model="form.password2" />
				<view class="iconfont " style="color: #a6a6a6;"
					:class="[isShowPwd2?'icon-app-yulan-close':'icon-app-yulan-open']" @click="switchIcon(2)"></view>
			</view>
			<view class="zdy-input">
				<input class="pwd-left" :password="isShowPwd3" name="password" placeholder="请确认新密码"
					v-model="form.password3" />
				<view class="iconfont " style="color: #a6a6a6;"
					:class="[isShowPwd3?'icon-app-yulan-close':'icon-app-yulan-open']" @click="switchIcon(3)"></view>
			</view>
		</view>

		<view class="comfir-btn">
			<view class="qd-btn" @click="updateNumberPhone">
				确&nbsp;&nbsp;定
			</view>
		</view>
	</view>
</template>

<script>
	import md5 from '@/common/md5.min.js';
	export default {
		data() {
			return {
				tips: '',
				numberphone: '', //手机号码
				yzmCode: '', //验证码
				currentPhone: '',
				isShowPwd: true,
				isShowPwd2: true,
				isShowPwd3: true,
				form: {
					password1: '',
					password2: '',
					password3: ''
				}
			}
		},
		onLoad(options) {
			this.currentPhone = options.currentphone;
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},

			change(e) {
				console.log('change', e);
			},
			switchIcon(type) {
				if (type == 1) {
					this.isShowPwd = !this.isShowPwd
				}
				if (type == 2) {
					this.isShowPwd2 = !this.isShowPwd2
				}
				if (type == 3) {
					this.isShowPwd3 = !this.isShowPwd3
				}
			},
			//提交
			updateNumberPhone() {
				var _this = this;
				if (!_this.form.password1) {
					uni.showToast({
						icon: 'none',
						title: '请输入原始密码'
					})
					return
				}
				if (!_this.form.password2) {
					uni.showToast({
						icon: 'none',
						title: '请输入新密码'
					})
					return
				}
				if (!_this.form.password3) {
					uni.showToast({
						icon: 'none',
						title: '确认新密码不能为空'
					})
					return
				}
				if (!/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&.*]+$)[a-zA-Z\d!@#$%^&.*]{6,16}$/.test(_this.form.password2)) {
					return uni.$u.toast('请输入由字母/数字/字符组成的6-16位密码');
				}

				if (_this.form.password2 && _this.form.password3) {
					if (_this.form.password2.trim().toString() !== _this.form.password3.trim().toString()) {
						uni.$u.toast('两次密码输入不一致')
						return
					}
				}
				uni.$u.http.post(`/base/mobile/userInfo/updatePwd`, {
					oldPwd: md5(_this.form.password1),
					userPwd: md5(_this.form.password2)
				}).then(res => {
					if (res.code == 0) {
						uni.$u.toast('密码修改成功！')
						// uni.clearStorageSync();
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/subPackagesD/mycenter/changepwdsuccess'
							})
						}, 500)

					} else {
						uni.$u.toast(res.message)
					}
				}).catch(err => {})
			}
		}
	}
</script>

<style lang="scss">
	.phone-title {
		font-size: 28rpx;
		padding: 32rpx 32rpx 24rpx 32rpx;
		background: #fff;
		color: #8C8C8C;
	}

	.input-wrapper {


		.zdy-input {
			margin: 40rpx 32rpx;
			font-size: 28rpx;
			border-radius: 6px;
			background: #F2F2F2;
			height: 96rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 24rpx 32rpx;
			box-sizing: border-box;

			.pwd-left {
				width: 90%;
				background: rgba(242, 242, 242, 1);
				border: none;
			}

			.iconfont {
				font-size: 40rpx;
			}

		}
	}

	.comfir-btn {
		width: 100%;
		height: 96rpx;
		margin-top: 64rpx;
		padding: 0 32rpx;
		box-sizing: border-box;

		.qd-btn {
			margin: 32rpx 0;
			height: 96rpx;
			line-height: 96rpx;
			border-radius: 12rpx;
			background: #0F53AC;
			color: #fff;
			font-size: 34rpx;
			text-align: center;
		}
	}
</style>